package swu.filter;

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpSessionEvent;
import jakarta.servlet.http.HttpSessionListener;

public class SessionOnline implements HttpSessionListener 
{
    @Override
    //获取session的方法
    public void sessionCreated(HttpSessionEvent se)
    {
        ServletContext servletContext = se.getSession().getServletContext();
        String id = se.getSession().getId();
        System.out.println(id);
        Integer online = (Integer) servletContext.getAttribute("Online");

        if(online == null)
        {
            online=new Integer(1);//运用封装类的知识
        }
        else
        {
            int count =online.intValue();
            online=new Integer(count+1);
        }
        servletContext.setAttribute("Online",online);

    }

    @Override

    public void sessionDestroyed(HttpSessionEvent se)
    {

    }
}


